package com.cnpc.rightslogan.service.impl;

import com.cnpc.rightslogan.entity.DictionaryType;
import com.cnpc.rightslogan.mapper.DictionaryTypeMapper;
import com.cnpc.rightslogan.service.IDictionaryTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class DictionaryTypeServiceImpl implements IDictionaryTypeService {

    @Resource
    private DictionaryTypeMapper dictionaryTypeMapper;

    @Override
    public DictionaryType getDictionaryType(int id) {
        DictionaryType dictionaryType = new DictionaryType();
        dictionaryType.setDicTypeId(id);
        return dictionaryTypeMapper.selectOne(dictionaryType);
    }

    @Override
    public DictionaryType getDictionaryType(DictionaryType dictionaryType) {
        return dictionaryTypeMapper.selectOne(dictionaryType);
    }

    @Override
    public PageInfo<DictionaryType> getDictionaryTypeList(Integer pageNum, Integer pageSize, DictionaryType dictionaryType) {
        PageHelper.startPage(pageNum, pageSize);
        List<DictionaryType> dictionaryTypeList = dictionaryTypeMapper.select(dictionaryType);
        return new PageInfo<>(dictionaryTypeList);
    }

    @Override
    public Integer addDictionaryType(DictionaryType dictionaryType) {
        return dictionaryTypeMapper.insert(dictionaryType);
    }

    @Override
    public Integer updateDictionaryType(DictionaryType dictionaryType) {
        return dictionaryTypeMapper.updateByPrimaryKeySelective(dictionaryType);
    }

    @Override
    public Integer deleteDictionaryType(DictionaryType dictionaryType) {
        return dictionaryTypeMapper.delete(dictionaryType);
    }
}